<?php
class ProductsController extends AppController {

	var $name = 'Products';
	var $uses = array('Category','Product');
	function index($id=null) {
		
		$lang=$this->Session->read('lag');
		if(! $id){
			$name=$_SERVER['HTTP_REFERER'];
			$this->redirect($name);
		}else{
			$arr[]=$id;
			$name=$this->Category->findById($id);
			$this->set('name_Ct',$name['Category']['name']);
			$this->set('introductions',$name['Category']['introduction']);
			$List_CT = $this->Category->find('list', array(
				'fields' => array('Category.id'),
				'conditions' => array('Category.status' => '1','Category.parent_id'=>$id),
				'recursive' => 0
				));				
			foreach($List_CT as $key){
				$arr[]=$key;
			}				
		
		// lay san pham va phan trang
			$conditions=array('OR'=>array('Product.category_id'=>$arr));
			$this->paginate = array('conditions' =>$conditions,'order'=>'Product.id DESC','limit' =>10);
			$this->set('products',$this->paginate('Product'));		
		}	
	}

}
?>